package com.bigdata.schaduler.client;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;
import org.jetbrains.annotations.NotNull;

import java.io.IOException;

public class TokenInterceptor implements Interceptor {

  private final String token;

  public TokenInterceptor(String token) {
    this.token = token;
  }

  @NotNull
  @Override
  public Response intercept(okhttp3.Interceptor.Chain chain) throws IOException {
    Request originalRequest = chain.request();
    Request newRequest = originalRequest.newBuilder()
        .header("token", token)
        .build();
    return chain.proceed(newRequest);
  }
}